package com.portal.cwegportal.service;

import com.appcenter.jz.page.PagedResult;
import com.appcenter.jz.unit.ObjectUnit;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.portal.cwegportal.input.browserecord.*;
import com.portal.cwegportal.mapper.BrowseRecordMapper;
import com.portal.cwegportal.model.BrowseRecord;
import com.portal.cwegportal.model.NewsCollege;
import com.portal.cwegportal.output.browserecord.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;
/**
 *  创建人:王增立
 *  备注: 浏览记录
 *  时间: 2019/4/26 14:49
 *  参数: 
 */
@Service
public class BrowseRecordService {
    @Autowired
    BrowseRecordMapper browseRecordMapper;
    @Transactional
    /**
     *  创建人:王增立
     *  备注: 创建浏览次数
     *  时间: 2019/4/26 14:50
     *  参数: 
     */
    public CreateBrowseRecordOutput createBrowseRecord(CreateBrowseRecordInput input) throws Exception {
        CreateBrowseRecordOutput output = new CreateBrowseRecordOutput();
        BrowseRecord browseRecord=new BrowseRecord();
        ObjectUnit.Copy(input.getItem(),browseRecord);
        browseRecord.setGmtCreate(new Date());
        browseRecord.setGmtModified(new Date());
        browseRecord.setDeleted(false);
        browseRecordMapper.insertSelective(browseRecord);
        output.setItem(browseRecord);
        return output;
    }

/**
 *  创建人:王增立
 *  备注: 删除浏览记录
 *  时间: 2019/4/26 14:51
 *  参数: 
 */
    public DeleteBrowseRecordOutput deleteBrowseRecord(DeleteBrowseRecordInput input) {
        DeleteBrowseRecordOutput output = new DeleteBrowseRecordOutput();
        BrowseRecord oldEntity = browseRecordMapper.selectByPrimaryKey(input.getItem().getId());
        oldEntity.setDeleted(true);
        browseRecordMapper.updateByPrimaryKey(oldEntity);
        return output;
    }

/**
 *  创建人:王增立
 *  备注: 获取浏览记录
 *  时间: 2019/4/26 15:17
 *  参数: 
 */
    public GetBroweCountOutput getBroweCount(GetBrowseCountInput input){
        return  browseRecordMapper.getBroweCount(input);
    }






}
